package com.whitecat.voting.util;

import com.whitecat.voting.constant.RespCode;
import com.whitecat.voting.entity.MpUserInfo;
import com.whitecat.voting.exception.BusinessException;
import org.apache.shiro.SecurityUtils;

public class ShiroUtils {

    public static MpUserInfo getSignInUser() {
        Object userObj = SecurityUtils.getSubject().getSession().getAttribute("mpUserInfo");
        if (userObj == null) {
            throw new BusinessException(RespCode.UNAUTHORIZED.getMessage(), RespCode.UNAUTHORIZED.getCode());
        }

        return ((MpUserInfo) userObj);
    }

    public static MpUserInfo getCurrentUser() {
        Object userObj = SecurityUtils.getSubject().getSession().getAttribute("mpUserInfo");
        return userObj == null ? null : ((MpUserInfo) userObj);
    }
}